//
//  FeedbackViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/29.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit
import SwiftyJSON

class FeedbackViewController: KMViewController {
    
    fileprivate var feedbackView : FeedbackView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = commentsAndFeedback
        addSubView()
    }

    //MARK: 添加视图
    fileprivate func addSubView() {
        
        feedbackView = FeedbackView.init(frame: self.view.bounds)
        feedbackView.submitBtn.addTarget(self, action: #selector(feedbackAction), for: .touchUpInside)
        self.view.addSubview(feedbackView)
    }
    
    //MARK: 意见反馈
    @objc fileprivate func feedbackAction() {
        
        if feedbackView.contactView.textView.text == "" {
            KMTool.showText(_text: inputContactInformation)
            return
        }
        
        if feedbackView.textView.text == "" {
            KMTool.showText(_text: inputYourFeedback)
            return
        }

        KMTool.waiting()
        KMTool.requestPostData(URLString: url_feedback, parameters: ["contact":feedbackView.contactView.text,"content":feedbackView.textView.text], progress: nil) { (data) in
            
            KMTool.stop()
            
            let json = JSON.init(data)
            
            if json["gid"].stringValue == "0" {
                self.navigationController?.popViewController(animated: true)
            }
            
            KMTool.showText(_text: json["msg"].stringValue)
            
        }
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }


}
